package servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dao.ContentsDAO;


@WebServlet("/servlet/DraftListServlet")
public class DraftListServlet extends HttpServlet{
	private ContentsDAO dao = new ContentsDAO();
	private String action ;
    protected void doGet(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
    protected void doPost(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        this.action = request.getParameter("action");
        if (action.equals("edit"))
	      {
        	contents_edit(request);
		
	      }
        else if(action.equals("delt"))
        {
        	contents_delt(request);
        }
        request.setAttribute("userno", request.getParameter("userno"));
      	request.getRequestDispatcher("/draftList.jsp").forward(request, response);   	
    }
    private void contents_edit(HttpServletRequest request){
   	 try {

   		 this.dao.passContents(request.getParameter("cno"),request.getParameter("userno"));
		 } catch (Exception ex) {
			 
	         request.setAttribute("errormsg", ex.getMessage());
	         
	     }
   }
    private void contents_delt(HttpServletRequest request) {
      	 try {
      		 this.dao.delContents(request.getParameter("cno"));

   	 } catch (Exception ex) {
   		 
            request.setAttribute("errormsg", ex.getMessage());
            
        }
    }
}
